/* 
 * ColorRenderer.java (compiles with releases 1.2, 1.3, and 1.4) is used by 
 * 
 */

package it.luigiarpino.sudoku;

import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTextField;


public class CellRendererSolution extends JTextField implements TableCellRenderer {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Sudoku s;
    
    public CellRendererSolution(Sudoku sud) {
        this.setOpaque(true); //MUST do this for background to show up.
        this.s=sud;
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object dato,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        this.setFont(new java.awt.Font("SansSerif", 0, 20));
        this.setBackground(new Color(255,255,255));
        this.setText(s.GetElemSol(row+1,column+1).toString());
        /*
         if (this.s.GetElemSchema(row+1,column+1).intValue()!=0){
            this.setForeground(new Color(35,92,219));
            this.setText(s.GetElemSchema(row+1,column+1).toString());
        }
        else{
            this.setForeground(new Color(0,0,0));
            Integer numero;
            try{
                numero=new Integer(dato.toString());
                if (numero.intValue()<1 || numero.intValue() >9){
                    this.setText("");
                }
                else{
                    this.setText(dato.toString());
                }
            }
            catch (java.lang.Exception e){
                numero=new Integer(0);
                this.setText("");
            }
        }
         */
        // imposta lo sfondo
        Color sfondo =new Color(200,200,200);
        if ((row>=0 && row<=2)&&(column>=3&& column<=5)){
           this.setBackground(sfondo);
        }
        if ((row>=3 && row<=5)&&((column>=0&& column<=2)||(column>=6&& column<=8))){
            this.setBackground(sfondo);
        }
        if ((row>=6 && row<=8)&&(column>=3&& column<=5)){
            this.setBackground(sfondo);
        }
        
        return this;
    }
    
}// fine classe
